import { createApp } from "vue";
import MessageIndex from '../components/MessageIndex.vue'

export type MessageType = 'success' | 'error' | 'default'

const createMessage = (message: string, type: MessageType, timeout = 2000) => {
    const messageInstanse = createApp(MessageIndex, {
        message,
        type
    })
    const mountNode = document.createElement('div')
    document.body.appendChild(mountNode)
    
    messageInstanse.mount(mountNode)

    // 卸载组件
    setTimeout(() => {
        messageInstanse.unmount()
        // 删除节点
        document.body.removeChild(mountNode)
    }, timeout)

}

export default createMessage